package com.jxb.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.security.core.Authentication;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/getCurrentUser")
    public Object getCurrentUser(Authentication authentication) {
        return authentication;
    }

//    @RequestMapping("/login")
//    public String login(String username, String password) {
//        //调用接口，进行授权获取token
//        //http://localhost:8080/oauth/token?username=fox&password=123456&grant_type=password&client_id=client&client_secret=123123&scope=all
//        String url = "http://localhost:8080/oauth/token?username=" + username
//                + "&password=" + password + "&grant_type=password&client_id=client&client_secret=123123&scope=all";
//        HttpHeaders headers = new HttpHeaders();
//        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
//        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
//
//        HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(params, headers);
//        ResponseEntity<TokenInfo> exchange = restTemplate.exchange(url, HttpMethod.GET, entity, TokenInfo.class);
//
//        return exchange.getBody().getAccess_token();
//    }
}